<?php

namespace App\Admin\Controllers;

use App\Models\CollPosition;
use App\Models\ExpressCompany;
use App\Models\PersonalUser;
use App\Models\Product;
use App\Models\ProductAttrKey;
use App\Models\Resume;
use Encore\Admin\Controllers\AdminController;
use App\Admin\Actions\Post\Restore;
use App\Admin\Actions\Post\productSKUList;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;


class ExpressCompanyController extends AdminController
{
    protected $title = '快递公司列表';

    protected static $baseImg = 'https://liande.oss-cn-beijing.aliyuncs.com';

    protected function grid()
    {
        $grid = new Grid(new ExpressCompany());

        $grid->column('id', __('Id号'));
        $grid->column('name', __('快递公司'));
        $grid->column('code', __('编码'));
        $grid->column('icon', __('快递公司图标'))->image(self::$baseImg, 100, 100);
        $grid->column('phone', __('固话'));

        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableColumnSelector();

        $grid->filter(function ($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('name', '快递公司名称');

        });

        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
        });

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(ExpressCompany::findOrFail($id));

        $show->field('name', __('快递公司'));
        $show->field('code', __('编码'));
        $show->field('icon', __('快递公司图标'))->image();
        $show->field('phone', __('固话'));

        $show->panel()
            ->tools(function ($tools) {
                $tools->disableDelete();
            });;

        return $show;
    }

    protected function form()
    {
        $form = new Form(new ExpressCompany());

        $form->text('name', __('快递公司'))->required();
        $form->text('code', __('编码'))->required();
        $form->image('icon', __('快递公司图标'));
        $form->text('phone', __('固话'));

        $form->tools(function (Form\Tools $tools) {
            // 去掉`删除`按钮
            $tools->disableDelete();
        });

        $form->footer(function ($footer) {
            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
        });

        return $form;
    }
}